'use strict';
module.exports = {
	/**
	 * 创建新订单
	 * @url client/pay/kh/makeRecharge 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			out_trade_no,
			cz_item,
			tv_id,
			tv_name,
			appid,
			appname,
			payPlatform,
			openid,
			virtualPayment
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		console.log("makeRecharge->originalParam=", originalParam);
		if (userInfo.clue_token && !userInfo.clickid) {
			//clickid得有值，否则会在回传处被return
			userInfo.clickid = userInfo.clue_token;
		}
		res.add_order = await db.collection('a_recharge').add({
			out_trade_no: out_trade_no,
			user_id: userInfo._id,
			nickname: userInfo.nickname || '未绑定昵称',
			recharge_amount: cz_item.recharge_amount,
			shifu_amount: 0,
			platform: payPlatform || "wxpay",
			transaction_id: "",
			pay_status: 0,
			bean: cz_item.bean,
			subject: cz_item.subject,
			user_register_date: userInfo.register_date,
			tv_id: tv_id || "直充",
			tv_name: tv_name || "直充",
			remark: cz_item.recharge_text || "",
			tfid: userInfo.tfid || 0,
			middleman_id: userInfo.middleman_id || 0,
			invite_code: userInfo.invite_code || 0,
			ad_id: userInfo.ad_id || userInfo.advertiser_id, //巨量的广告主ID
			clickid: userInfo.clickid || "", //巨量的广告点击识别ID
			os_name: originalParam.context.osName || "", //用户充值时的系统
			appid: appid || "NoAppid",
			appname: appname || "NoAppname",
			tg_pt: userInfo.tg_pt || '',
			ip: originalParam.context.CLIENTIP,
			province: userInfo.province, //省份
			city: userInfo.city, //市
			pageId: userInfo.pageId, //oppo广告专属-网页ID
			commission_is: false, //记录订单是否已结算
			_add_time: new Date().getTime(),
			
			openid:openid,
			env:0,  // 现网环境
			virtualPayment:virtualPayment
		})

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}